home *** CD-ROM | disk | FTP | other *** search
/ Aminet 52 / Aminet 52 (2002)(GTI - Schatztruhe)[!][Dec 2002].iso / Aminet / dev / lang / amigatalk.lha / system / ParallelDevice.st < prev    next >
Text File  |  2002-03-15  |  5KB  |  154 lines

  1. " ----------------------------------------------------------------------"
  2. " ParallelDevice Class is derived from abstract Device Class.           "
  3.  
  4. "  WARNING:  You should know what you're doing to the Amiga OS before   "
  5. "            messing with this Class, or any other System Class!        " 
  6.  
  7. " This class is a Singleton Class.  In the future, this class will be   "
  8. " modified to allow more than one Parallel port to be open at a time    "
  9. " (for those of us fortunate enough to have more than one Parallel Port."
  10.  
  11. " NOTES
  12.  
  13.   newParms & parallelFlags can have any of the following values:
  14.  
  15.     2r00000010 PARF_EOFMODE  - check I/O against the TermChars array.
  16.     2r00000100 PARF_ACKMODE  - use ACK handshaking.
  17.     2r00001000 PARF_FASTMODE - Send out data as long as BUSY is low. 
  18.     2r00010000 PARF_SLOWMODE - For transfers to slow printers.
  19.     2r00100000 PARF_SHARED   - Allow sharing of the parallel device.    "
  20. ""
  21. " ALL singleton classes MUST contain the following:                     "
  22. "" 
  23. "   the methods:  isSingleton AND privateSetup     AND                  "
  24. "                 uniqueInstance Class instance variable.               "
  25. " ----------------------------------------------------------------------"
  26.  
  27. Class ParallelDevice :Device ! uniqueInstance flagDictionary !
  28. [
  29.    isSingleton
  30.      ^ true
  31.    status
  32.      "  The returned status has the following meaning:
  33.      *
  34.      *  BIT:  ACTIVE:  FUNCTION:
  35.      *
  36.      *  0      HIGH   Printer Busy toggle (offline).
  37.      *  1      HIGH   Paper out.
  38.      *  2      HIGH   Printer Select.
  39.      *  3      ----   Read = 0, Write = 1
  40.      *  4-7    ----   Reserved.
  41.      "
  42.       ^ <primitive 224 3>
  43. |
  44.    resetPort
  45.       ^ <primitive 224 4>
  46. |                  
  47.    flushPort
  48.       ^ <primitive 224 5>
  49. |                  
  50.    stopPort
  51.       ^ <primitive 224 6>
  52. |                  
  53.    startPort
  54.       ^ <primitive 224 7>
  55. |                  
  56.    setPortParametersTo: newParms
  57.       ^ <primitive 224 8 newParms>
  58. |                  
  59.    readThisMany: numChars
  60.       ^ <primitive 224 9 numChars>
  61. |
  62.    writeToPort: aString thisLong: numChars ! check !
  63.       check <- <primitive 224 10 numChars aString>.
  64.       
  65.       (check ~= numChars)
  66.          ifTrue: [ 'Parallel Port write error!' print]
  67. |                  
  68.    setTerminatorsTo: aString
  69.       "Only the first 4 characters of the string are used."
  70.       ^ <primitive 224 11 aString>
  71. |                  
  72.    setPortDirectionAtomic: rwFlag
  73.       " Not needed for reading & writing to the Parallel Port."
  74.       ^ <primitive 224 12 rwFlag>
  75. |                  
  76.    sendPortControlBits: newBits
  77.       " Only the 3 least-significant bits will be written to the hardware.
  78.         This is to prevent your code from interfering with the Serial
  79.         device.
  80.       "
  81.       ^ <primitive 224 13 newBits>
  82. |                  
  83.    readControlBitsMaskedBy: ctrlMask
  84.       " Only the 3 least-significant bits have any meaning 
  85.         for the Parallel Port.  Use ctrlMask of seven (7).
  86.       "
  87.       ^ <primitive 224 14 ctrlMask>
  88. |
  89.    open: parallelFlags ! check !
  90.    
  91.       check <- <primitive 224 1 parallelFlags>.
  92.  
  93.       (check ~= 0)
  94.          ifTrue: [ 'Error open Parallel device:' print.
  95.                    <primitive 224 2 check> print.
  96.                    ^ nil
  97.                  ].
  98.       ^ self
  99. |
  100.    close
  101.       <primitive 224 0>
  102. |
  103.    privateNew ! newinstance !
  104.      newinstance <- super new.
  105.  
  106.      ^ newinstance
  107. |
  108.    new
  109.      ^ self privateSetup
  110. |
  111.    privateInitializeDictionary
  112.      
  113.      flagDictionary at: #PARF_EOFMODE  put: 2r00000010. "check I/O against the TermChars array"
  114.      flagDictionary at: #PARF_ACKMODE  put: 2r00000100. " use ACK handshaking "
  115.      flagDictionary at: #PARF_FASTMODE put: 2r00001000. " Send out data as long as BUSY is low"
  116.      flagDictionary at: #PARF_SLOWMODE put: 2r00010000. " For transfers to slow printers"
  117.      
  118.      " Allow sharing of the parallel device.  This flag is required
  119.      * at all times:
  120.      "
  121.      flagDictionary at: #PARF_SHARED   put: 2r00100000. 
  122. |
  123.    getParFlag: aKey
  124.      ^ flagDictionary at: aKey
  125. |
  126.    privateSetup
  127.      (uniqueInstance isNil)
  128.        ifTrue: [uniqueInstance <- self privateNew.
  129.                 flagDictionary <- Dictionary new.
  130.                 
  131.                 self privateInitializeDictionary.
  132.                ].
  133.                
  134.      ^ self    "or ^ uniqueInstance??"
  135. |
  136.    current
  137.      ^ self privateSetup
  138. |
  139.    current: parallelFlags
  140.      (uniqueInstance isNil)
  141.         ifTrue: [ uniqueInstance <- self privateNew.
  142.                   flagDictionary <- Dictionary new.
  143.                 
  144.                   self privateInitializeDictionary.
  145.                   self open: parallelFlags
  146.                 ].
  147.       
  148.      ^ uniqueInstance
  149. |
  150.    new: parallelFlags
  151.      ^ (self current: parallelFlags)
  152. ]
  153.